/*DEFAULT STARTING STYLE
* ALL STYLES *MUST* HAVE SAME CSS PROPERTY AND VALUES
* ALL CLASS *MUST* BE IN SAME ORDER AS DEFAULT STYLE (NO ADDING STYLE POSIBILE IN DIRECT DB INSERT)
* 
* 
* 
*/
var style_default ={
    "pollbox": {
        "background-color": "#FAFAFA",
        "background-image": "",
        "background-repeat": "no-repeat",
        "background-position": "left top",
        "border-width": "1px",
        "border-style": "solid",
        "border-color": "#DEDEDE",
        "border-radius": "12px",
        "margin-top": "0px",
        "margin-right": "0px",
        "margin-bottom": "0px",
        "margin-left": "0px",
        "padding-top": "12px",
        "padding-right": "12px",
        "padding-bottom": "12px",
        "padding-left": "12px",
        "width": "300px",
        "height": "auto"
            
    },
    "question": {
        "font-family": "Arial",
        "color": "#333333",
        "font-size": "15px",
        "font-weight": "bold",
        "font-style": "normal",
        "line-height": "20px",
        "text-align": "left",
        "text-decoration": "none",
        "text-indent": "0px",
        "background-color": "",
        "background-image": "",
        "background-repeat": "no-repeat",
        "background-position": "center",
        "border-width": "0px",
        "border-style": "none",
        "border-color": "#333333",
        "border-radius": "0",
        "margin-top": "0px",
        "margin-right": "0px",
        "margin-bottom": "15px",
        "margin-left": "0px",
        "padding-top": "0px",
        "padding-right": "0px",
        "padding-bottom": "0px",
        "padding-left": "0px",
        "width": "auto",
        "height": "auto",
        "overflow": "hidden"      
    },
    "answergroup": {
        "padding-top": "5px",
        "padding-right": "0px",
        "padding-bottom": "5px",
        "padding-left": "0px"       
    },
    "answercheck": {
        "padding-top": "2px",
        "padding-right": "0px",
        "padding-bottom": "0px",
        "padding-left": "0px"       
    },
    "answers": {
        "font-family": "Arial",
        "color": "#333333",
        "font-size": "13px",
        "font-weight": "normal",
        "font-style": "normal",
        "line-height": "14px",
        "text-align": "left",
        "text-decoration": "none",
        "text-indent": "0px",            
        "padding-top": "0px",
        "padding-right": "0px",
        "padding-bottom": "0px",
        "padding-left": "0px",
        "width": "260px",
        "overflow": "hidden"       
    },
    "otherinput": {
        "font-family": "Arial",
        "color": "#333333",
        "font-size": "12px",
        "font-weight": "normal",
        "font-style": "normal",
        "line-height": "12px",
        "text-align": "left",
        "text-decoration": "none",
        "background-color": "",
        "background-image": "",
        "background-repeat": "no-repeat",
        "background-position": "center",
        "border-width": "1px",
        "border-style": "solid",
        "border-color": "#D1D1D1",
        "border-radius": "0px",
        "margin-top": "4px",
        "margin-right": "0px",
        "margin-bottom": "0px",
        "margin-left": "0px",
        "padding-top": "2px",
        "padding-right": "2px",
        "padding-bottom": "2px",
        "padding-left": "2px",       
        "width": "200px"       
    },
    "votebutton": {
        "font-family": "Arial",
        "color": "#333333",
        "font-size": "13px",
        "font-weight": "bold",
        "font-style": "normal",
        "line-height": "24px",
        "text-align": "left",
        "text-decoration": "none",
        "text-indent": "0px",
        "background-color": "#F2F2F2",
        "background-image": "url("+sys_url+"assets/img/backgrounds/but.png)",
        "background-repeat": "repeat-x",
        "background-position": "left top",
        "border-width": "1px",
        "border-style": "solid",
        "border-color": "#999999",
        "border-radius": "12px",
        "margin-top": "18px",
        "margin-right": "0px",
        "margin-bottom": "9px",
        "margin-left": "0px",
        "padding-top": "0px",
        "padding-right": "24px",
        "padding-bottom": "0px",
        "padding-left": "24px",      
        "display": "block",
        "width": "auto",
        "height": "auto",
        "overflow": "hidden"                    
    },
    "viewresults": {
        "background-color": "#F2F2F2",
        "background-image": "url("+sys_url+"assets/img/backgrounds/but.png)",
        "background-repeat": "repeat-x",
        "background-position": "left top",
        "margin-top": "18px",
        "margin-right": "0px",
        "margin-bottom": "9px",
        "margin-left": "5px",
        "width": "auto",
        "height": "auto"
    },
    "links": {
        "font-family": "Arial",
        "color": "#333333",
        "font-size": "11px",
        "font-weight": "normal",
        "font-style": "normal",
        "line-height": "26px",
        "text-align": "left",
        "text-decoration": "underline",
        "text-indent": "0px",            
        "padding-top": "18px",
        "padding-right": "10px",
        "padding-bottom": "0px",
        "padding-left": "0px",
        "overflow": "hidden"                
    },
    "resultsbackground": {
        "background-color": "",
        "background-image": "",
        "background-repeat": "repeat-x",
        "background-position": "center",
        "border-width": "1px",
        "border-style": "solid",
        "border-color": "#D1D1D1",
        "border-radius": "0px",             
        "padding-top": "0px",
        "padding-right": "0px",
        "padding-bottom": "0px",
        "padding-left": "0px", 
        "margin-top": "4px",
        "margin-right": "0px",
        "margin-bottom": "18px",
        "margin-left": "0px"
    },
    "resultsbar": {
        "background-color": "#FF9900",
        "background-image": "",
        "background-repeat": "repeat-x",
        "background-position": "center",
        "border-width": "0px",
        "border-style": "solid",
        "border-color": "#D1D1D1",
        "border-radius": "0px",             
        "padding-top": "0px",
        "padding-right": "0px",
        "padding-bottom": "0px",
        "padding-left": "0px", 
        "margin-top": "0px",
        "margin-right": "0px",
        "margin-bottom": "0px",
        "margin-left": "0px",   
        "height": "14px"   
    },
    "totalvotes": {
        "font-family": "Arial",
        "color": "#333333",
        "font-size": "11px",
        "font-weight": "normal",
        "font-style": "normal",
        "line-height": "26px",
        "text-align": "left",
        "text-decoration": "none",
        "text-indent": "0px",
        "background-color": "",
        "background-image": "",
        "background-repeat": "repeat-x",
        "background-position": "center",
        "border-width": "0px",
        "border-style": "none",
        "border-color": "none",
        "border-radius": "0px",             
        "padding-top": "0px",
        "padding-right": "0px",
        "padding-bottom": "0px",
        "padding-left": "0px", 
        "margin-top": "0px",
        "margin-right": "0px",
        "margin-bottom": "0px",
        "margin-left": "0px",
        "overflow": "hidden"         
    }
}
var pollbox = new Array('Background','Border','Margin','Padding','Width','Height');
var question = new Array('Font','Background','Border','Margin','Padding','Width','Height');
var answergroup = new Array('Padding');
var answercheck = new Array('Padding');
var answers_ar = new Array('Font','Padding','Width');
var otherinput = new Array('Font','Background','Border','Margin','Padding','Width');
var votebutton = new Array('Font','Background','Border','Margin','Padding','Width','Height');
var viewresults = new Array('Background','Margin','Width','Height');
var links = new Array('Font','Padding');
var resultsbackground = new Array('Background','Border','Margin','Padding');
var resultsbar = new Array('Background','Border','Margin','Padding','Height');
var totalvotes = new Array('Font','Background','Border','Padding');
var flipped = false;
var properties = new Array(
"font-family",
"color",
"font-size",
"font-weight",
"font-style",
"line-height",
"text-align",
"text-decoration",
"text-indent",
"background-color",
"background-image",
"background-repeat",
"background-position",
"border-width",
"border-style",
"border-color",
"border-radius",
"margin-top",
"margin-right",
"margin-bottom",
"margin-left",
"padding-top",
"padding-right",
"padding-bottom",
"padding-left",
"width", 
"height"
);
function renderStyleEdit(render){
    var curr_array;
    var flipp = false;
    switch (render){
        case 'lss-box': curr_array = pollbox; active_node = 'pollbox';             
            break;
        case 'lss-question-top': curr_array = question; active_node = 'question'; 
            break;
        case 'lss-answer-group': curr_array = answergroup; active_node = 'answergroup';
            break;
        case 'lss-answer-input': curr_array = answercheck; active_node = 'answercheck';
            break;
        case 'lss-answer': curr_array = answers_ar; active_node = 'answers';
            break;
        case 'lss-textfield':  curr_array = otherinput; active_node = 'otherinput';
            break;
        case 'lss-vote-button': curr_array = votebutton; active_node = 'votebutton';
            break;
        case 'lss-view-results': curr_array = viewresults; active_node = 'viewresults';
            break;
        case 'lss-link': curr_array = links; active_node = 'links';
            break;
        case 'lss-answer-feedback': curr_array = resultsbackground; active_node = 'resultsbackground'; flipp = true;            
            break;
        case 'lss-answer-feedback-bar': curr_array = resultsbar; active_node = 'resultsbar'; flipp = true; 
            break;
        case 'lss-totalvotes-inner': curr_array = totalvotes; active_node = 'totalvotes'; flipp = true; 
            break;
    } 
    if(flipp){
        if(!flipped){
            $('body').trigger('priview_result');
            flipped = true;
        } 
    }else{
        if(flipped){
            $('body').trigger('priview_poll');
            flipped = false;
        } 
    } 
    /*RESETUJE CHECKBOX NA CSSE EDITORU*/
    $.each(properties, function(index,property){
        if(property=='font-weight'){
            $("#"+property).attr('checked', false);
        }else if(property=='font-style'){
            $("#"+property).attr('checked',false);
        }else if(property=='text-decoration'){
            $("#"+property).attr('checked',false);
        }else if(property=='text-indent'){
            $("#"+property).attr('checked',false);
        }
    });
    /*POPUNJAVA KOMPONENTE NA CSSE EDITORU*/
    $.each(properties, function(index,property){
        if((property=='font-weight')&& (find_value(property)=='bold')){
            $("#"+property).attr('checked','checked');
        }else if((property=='font-style')&& (find_value(property)=='italic')){
            $("#"+property).attr('checked','checked');
        }else if((property=='text-decoration')&& (find_value(property)=='underline')){
            $("#"+property).attr('checked','checked');
        }else if((property=='text-indent')&& (find_value(property)=="-99999")){
            $("#"+property).attr('checked','checked');      
        }else if((property=='width')|| (property=='height')){
            $("#"+property).val(find_value(property)); 
        }else $("#"+property).val(find_value(property));
    });         
    $('.main > a').removeClass('on');
    $('.sub > a').removeClass('top on'); 
    $('#a-'+render).addClass('on');      
    $('.sub > a').hide();                
    $('.sub a').each(function(index) {
        var property_id = this.id.substring(2, this.id.length);
        if(jQuery.inArray(property_id, curr_array)>-1){
            $(this).css('display','block');   
        }                         
    });  
    $('#A_'+curr_array[0]).addClass('top on');
    $('#properties > div').hide();
    $('#edit'+curr_array[0]).show();
}
function find_value(property){       
    if(((property=='background-color')||(property=='border-color')||(property=='color'))&&(klase_stilovi[active_node][property]!=undefined)){
        if(klase_stilovi[active_node][property]=='none'){
            return klase_stilovi[active_node][property];    
        }else if(klase_stilovi[active_node][property]=='transparent'){
            return '';  
        }else return klase_stilovi[active_node][property].substring(1,klase_stilovi[active_node][property].length);
    }else if((property=='background-image')&&(klase_stilovi[active_node][property]!=undefined)){
        return klase_stilovi[active_node][property].substring(4,klase_stilovi[active_node][property].length-1);   
    }
    else return klase_stilovi[active_node][property];
}
function CSSE_changeView(property){ 
    $('.sub > a').removeClass('on');
    $('#A_'+property).addClass('on');
    $('#properties > div').hide();
    $('#edit'+property).show();
}
function bind(comp){
    var property = comp.id;
    if(property=='font-weight'){
        if($("#"+property).is(':checked')) {
            comp.value = 'bold';              
        }
        else {
            comp.value = 'normal';                    
        }
    }
    if(property=='font-style'){
        if($("#"+property).is(':checked')) {
            comp.value = 'italic';              
        }
        else {
            comp.value = 'normal';                    
        }
    }
    if(property=='text-decoration'){
        if($("#"+property).is(':checked')) {
            comp.value = 'underline';              
        }
        else {
            comp.value = 'none';                    
        }
    }
    if(property=='text-indent'){
        if($("#"+property).is(':checked')) {
            comp.value = '-99999px';                
        }
        else {
            comp.value = 0;                    
        }
    }
    if(property=='background-image'){
        if(comp.value.substring(0,3)!='url'){
            klase_stilovi[active_node][property] = 'url('+comp.value+')';        
            preview_style(property, 'url('+comp.value+')');
        }else{
            klase_stilovi[active_node][property] = comp.value;        
            preview_style(property, comp.value);
        }             
    }else if((active_node=='answergroup')&&(property=='padding-top')){  //IE PADDING FIX
        if(comp.value=='0px')comp.value='1px';
        klase_stilovi[active_node][property] = comp.value;        
        preview_style(property, comp.value); 
    }else{
        klase_stilovi[active_node][property] = comp.value;        
        preview_style(property, comp.value); 
        
    }
}
function bind_background(property, value){
    klase_stilovi[active_node][property] = value; 
    preview_style(property, value);        
} 
function preview_style(property, value,test){
    if ($.browser.mozilla){
        if (property=='border-radius') property='-moz-border-radius'
    }
    switch(active_node){
        case 'pollbox':    
            $('.lss-box').css(property, value);     
            break;
        case 'question':
            $('.lss-question-top').css(property, value);             
            break;
        case 'answergroup':
            $('.lss-answer-group').css(property, value);               
            break;
        case 'answercheck':
            $('.lss-answer-input').css(property, value);             
            break;
        case 'answers':
            $('head').append("<style type='text/css'>.lss-answer-span{"+property+":"+value+"}</style>");               
            break;
        case 'otherinput':
            $('.lss-textfield').css(property, value);               
            break;
        case 'votebutton':
            $('.lss-vote-button').css(property, value);               
            break;
        case 'viewresults':
            $('.lss-view-results').css(property, value);               
            break;
        case 'links':
            $('head').append("<style type='text/css'>#lss-links a{"+property+":"+value+"}</style>");
            break;
        case 'resultsbackground':
            $('head').append("<style type='text/css'>.lss-result-feedback{"+property+":"+value+"}</style>");             
            break;
        case 'resultsbar':
            $('.lss-result-feedback-bar').css(property, value);               
            break;
        case 'totalvotes':
            $('.lss-totalvotes-inner').css(property, value);               
            break;
    }        
}
function showNote($note_type){
    switch($note_type){
        case 'noteImageURL':
            alert('Ovde unesite link do slike koju želite da postavite kao pozadinu, npr.( http://www.logicsolution.rs/assets/img/logo.png )')
            break;
        case 'notePollWidth':
            alert('Ovde unesite širinu u pikselima vaše ankete. Ukoliko smanjite anketu, trebalo bi da proverite širinu vaših odgovora.')
            break;
    }    
}